#include <iostream>
#include <assert.h>
using namespace std;

class Date
{
public:
	Date(int year = 1, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}

	bool operator<(Date& x);
	bool operator>(Date& x);
	bool operator<=(Date& x);
	bool operator>=(Date& x);
	bool operator==(Date& x);

	Date& operator+=(int day);
	Date operator+(int day);
	Date& operator-=(int day);
	Date operator-(int day);

	void print()
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}


	int GetMonthDay(int year, int month)
	{
		assert(month > 0 && month < 13);

		static int Day[13] = { -1,31,28,31,30,31,30,31,31,30,31,30,31 };

		if (month == 2 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0))
		{
			return 29;
		}

		return Day[month];
	}

	


private:
	int _year;
	int _month;
	int _day;
};

bool Date::operator<(Date& x)
{
	if (_year < x._year)
	{
		return true;
	}
	else if (_year == x._year && _month < x._month)
	{
		return true;
	}
	else if (_year == x._year && _month == x._month && _day < x._day)
	{
		return true;
	}

	return false;
}

bool Date::operator>(Date& x)
{
	return !(*this <= x);
}

bool Date::operator<=(Date& x)
{
	return *this < x || *this == x;
}

bool Date::operator>=(Date& x)
{
	return !(*this < x);
}

bool Date::operator==(Date& x)
{
	return _year == x._year && _month == x._month && _day == x._day;
}

Date& Date::operator+=(int day)
{
	_day += day;

	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		++_month;

		if (_month == 13)
		{
			++_year;
			_month = 1;
		}
	}

	return *this;
}

Date Date::operator+(int day)
{
	Date tmp = *this;

	tmp += day;

	return tmp;
}

Date& Date::operator-=(int day)
{
	_day -= day;

	while (_day <= 0)
	{
		--_month;

		if (_month == 0)
		{
			--_year;
			_month = 12;
		}

		_day += GetMonthDay(_year, _month);
	}

	return *this;
}

Date Date::operator-(int day)
{
	Date tmp = *this;

	tmp -= day;

	return tmp;
}

int main()
{
	Date a(2024, 8, 21);
	a += 11;
	a.print();

	Date b = a + 10;
	a.print();
	b.print();

	Date c(2024, 8, 20);
	c - 15;
	c.print();
	c -= 15;
	c.print();

	return 0;
}